﻿using System;
using System.Collections.Generic;
using GeoAPI.Geometries;
using NetTopologySuite.GeometriesGraph;

namespace NetTopologySuite.Operation.Overlay
{
	public class MaximalEdgeRing : EdgeRing
	{
		public MaximalEdgeRing(DirectedEdge start, IGeometryFactory geometryFactory) : base(start, geometryFactory)
		{
		}

		public override DirectedEdge GetNext(DirectedEdge de)
		{
			return de.Next;
		}

		public override void SetEdgeRing(DirectedEdge de, EdgeRing er)
		{
			de.EdgeRing = er;
		}

		public void LinkDirectedEdgesForMinimalEdgeRings()
		{
			DirectedEdge directedEdge = this.startDe;
			do
			{
				((DirectedEdgeStar)directedEdge.Node.Edges).LinkMinimalDirectedEdges(this);
				directedEdge = directedEdge.Next;
			}
			while (directedEdge != this.startDe);
		}

		public IList<EdgeRing> BuildMinimalRings()
		{
			IList<EdgeRing> list = new List<EdgeRing>();
			DirectedEdge directedEdge = this.startDe;
			do
			{
				if (directedEdge.MinEdgeRing == null)
				{
					EdgeRing item = new MinimalEdgeRing(directedEdge, base.GeometryFactory);
					list.Add(item);
				}
				directedEdge = directedEdge.Next;
			}
			while (directedEdge != this.startDe);
			return list;
		}
	}
}
